home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / cool / cool.lha / ice / pisces / rcs / rcsfcmp.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-09-04  |  7.1 KB  |  230 lines

  1. /*
  2.  *                     RCS file comparison
  3.  */
  4. #ifndef lint
  5. static char rcsid[]= "$Id: rcsfcmp.c,v 1.1 90/05/21 13:43:02 neath Exp $ Purdue CS";
  6. #endif
  7. /*****************************************************************************
  8.  *                       rcsfcmp()
  9.  *                       Testprogram: define FCMPTEST
  10.  *****************************************************************************
  11.  */
  12.  
  13. /* Copyright (C) 1982, 1988, 1989 Walter Tichy
  14.    Distributed under license by the Free Software Foundation, Inc.
  15.  
  16. This file is part of RCS.
  17.  
  18. RCS is free software; you can redistribute it and/or modify
  19. it under the terms of the GNU General Public License as published by
  20. the Free Software Foundation; either version 1, or (at your option)
  21. any later version.
  22.  
  23. RCS is distributed in the hope that it will be useful,
  24. but WITHOUT ANY WARRANTY; without even the implied warranty of
  25. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  26. GNU General Public License for more details.
  27.  
  28. You should have received a copy of the GNU General Public License
  29. along with RCS; see the file COPYING.  If not, write to
  30. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  31.  
  32. Report problems and direct all questions to:
  33.  
  34.     rcs-bugs@cs.purdue.edu
  35.  
  36. */
  37.  
  38.  
  39.  
  40.  
  41.  
  42. /* $Log:    rcsfcmp.c,v $
  43.  * Revision 1.1  90/05/21  13:43:02  neath
  44.  * Initial revision
  45.  * 
  46.  * Revision 4.5  89/05/01  15:12:42  narten
  47.  * changed copyright header to reflect current distribution rules
  48.  * 
  49.  * Revision 4.4  88/11/08  12:01:33  narten
  50.  * changes from  eggert@sm.unisys.com (Paul Eggert)
  51.  * 
  52.  * Revision 4.4  88/08/09  19:12:50  eggert
  53.  * Shrink stdio code size.
  54.  * 
  55.  * Revision 4.3  87/12/18  11:40:02  narten
  56.  * lint cleanups (Guy Harris)
  57.  * 
  58.  * Revision 4.2  87/10/18  10:33:06  narten
  59.  * updting version number. Changes relative to 1.1 actually relative to 
  60.  * 4.1
  61.  * 
  62.  * Revision 1.2  87/03/27  14:22:19  jenkins
  63.  * Port to suns
  64.  * 
  65.  * Revision 1.1  84/01/23  14:50:23  kcs
  66.  * Initial revision
  67.  * 
  68.  * Revision 4.1  83/05/10  16:24:04  wft
  69.  * Marker matching now uses trymatch(). Marker pattern is now
  70.  * checked precisely.
  71.  * 
  72.  * Revision 3.1  82/12/04  13:21:40  wft
  73.  * Initial revision.
  74.  *
  75.  */
  76.  
  77. /*
  78. #define FCMPTEST
  79. /* Testprogram; prints out whether two files are identical,
  80.  * except for keywords
  81.  */
  82.  
  83. #include  "rcsbase.h"
  84. extern FILE * fopen();
  85. extern enum markers trymatch(); /* check for keywords */
  86.  
  87.  
  88. rcsfcmp(xfname,uxfname,delta)
  89. char * xfname, *uxfname; struct hshentry *delta;
  90. /* Function: compares the files xfname and uxfname. Returns true
  91.  * if xfname has the same contents as uxfname, while disregarding
  92.  * keyword values. For the LOG-keyword, rcsfcmp skips the log message
  93.  * given by the parameter delta in xfname. Thus, rcsfcmp returns true
  94.  * if xfname contains the same as uxfname, with the keywords expanded.
  95.  * Implementation: character-by-character comparison until $ is found.
  96.  * If a $ is found, read in the marker keywords; if they are real keywords
  97.  * and identical, read in keyword value. If value is terminated properly,
  98.  * disregard it and optionally skip log message; otherwise, compare value.
  99.  */
  100. {
  101.     register int xc,uxc;
  102.     char xkeyword[keylength+2],   uxkeyword[keylength+2];
  103.     char xkeyval[keyvallength+1], uxkeyval[keyvallength+1];
  104.     register FILE * xfp, * uxfp;
  105.     register char * tp;
  106.     int result;
  107.     enum markers match1,match2;
  108.  
  109.     if ((xfp=fopen(tp=xfname,"r"))==NULL || (uxfp=fopen(tp=uxfname,"r"))==NULL) {
  110.        faterror("Can't open %s\n", tp);
  111.        return false;
  112.     }
  113.     result=false;
  114.     xc=getc(xfp); uxc=getc(uxfp);
  115.     while( xc == uxc) { /* comparison loop */
  116.         if (xc==EOF) { /* finished; everything is the same*/
  117.             result=true;
  118.             break;
  119.         }
  120.         if ( xc!=KDELIM) {
  121.             /* get the next characters */
  122.             xc=getc(xfp); uxc=getc(uxfp);
  123.         } else {
  124.             /* try to get both keywords */
  125.             tp = xkeyword;
  126.             while( (xc=getc(xfp))!=EOF && (tp< xkeyword+keylength) && (xc!='\n')
  127.                    && (xc!=KDELIM) && (xc!=VDELIM))
  128.                 *tp++ = xc;
  129.         *tp++ = xc;  /* add closing K/VDELIM */
  130.             *tp='\0';
  131.             tp = uxkeyword;
  132.             while( (uxc=getc(uxfp))!=EOF && (tp< uxkeyword+keylength) && (uxc!='\n')
  133.                    && (uxc!=KDELIM) && (uxc!=VDELIM))
  134.                 *tp++ = uxc;
  135.         *tp++ = xc;  /* add closing K/VDELIM */
  136.             *tp='\0';
  137.             /* now we have 2 keywords, or something thal looks like it.*/
  138.         match1=trymatch(xkeyword,false);
  139.         match2=trymatch(uxkeyword,false);
  140.         if (match1 != match2) break; /* not identical */
  141. #ifdef FCMPTEST
  142.         VOID printf("found potential keywords %s and %s\n",xkeyword,uxkeyword);
  143. #endif
  144.  
  145.         if (match1 == Nomatch) {
  146.         /* not a keyword pattern, but could still be identical */
  147.         if (strcmp(xkeyword,uxkeyword)==0)
  148.              continue;
  149.         else break;
  150.         }
  151. #ifdef FCMPTEST
  152.         VOID printf("found common keyword %s\n",xkeyword);
  153. #endif
  154.         tp=xkeyval;
  155.         if (xc==VDELIM) {/* get value */
  156.         while (((xc=getc(xfp))!=KDELIM) && (xc!='\n') && (xc!=EOF) &&
  157.             (tp<xkeyval+keyvallength))
  158.             *tp++ = xc;
  159.         }
  160.         *tp = '\0';   /*xkeyval now filled with value; possibly empty*/
  161.         tp=uxkeyval;
  162.         if (uxc==VDELIM) {/* get value */
  163.         while (((uxc=getc(uxfp))!=KDELIM) && (uxc!='\n') && (uxc!=EOF) &&
  164.             (tp<uxkeyval+keyvallength))
  165.             *tp++ = uxc;
  166.         }
  167.         *tp = '\0';   /*uxkeyval now filled with value; possibly empty*/
  168.         if (xc!=uxc) break; /* not the same */
  169.         if (xc==KDELIM) {
  170.         xc=getc(xfp); uxc=getc(uxfp); /* skip closing KDELIM */
  171.         /* if the keyword is LOG, also skip the log message in xfp*/
  172.         if (match1==Log) {
  173.             /* first, compute the number of line feeds in log msg */
  174.             int lncnt, ccnt;
  175.             lncnt=2; tp=delta->log;
  176.             while(*tp) if(*tp++=='\n') lncnt++;
  177.             while(xc!=EOF) {
  178.             if (xc=='\n')
  179.                 if(--lncnt==0) break;
  180.             xc=getc(xfp);
  181.             }
  182.             /* skip last comment leader */
  183.             /* Can't just skip another line here, because there may be */
  184.             /* additional characters on the line (after the Log....$)  */
  185.             for (ccnt=strlen(Comment); ccnt>=0; lncnt--) {
  186.             xc=getc(xfp);
  187.             if(xc=='\n') break;
  188.             /* reads to the end of the comment leader or '\n',     */
  189.             /* whatever comes first. This is because some editors  */
  190.             /* strip off trailing blanks from a leader like " * ". */
  191.             }
  192.         }
  193.         } else {
  194.         /* both end in the same character, but not a KDELIM */
  195.         /* must compare string values.*/
  196. #ifdef FCMPTEST
  197.         VOID printf("non-terminated keywords %s, potentially different values\n",xkeyword);
  198. #endif
  199.         if (strcmp(xkeyval,uxkeyval)!=0) break; /*different */
  200.         xc=getc(xfp); uxc=getc(uxfp); /* skip closing char  */
  201.             }
  202.         }
  203.     }
  204.     VOID fclose(xfp); VOID fclose(uxfp);
  205.     return result;
  206. }
  207.  
  208.  
  209.  
  210. #ifdef FCMPTEST
  211. char * RCSfilename, * workfilename;
  212.  
  213. char * Comment;
  214.  
  215. main(argc, argv)
  216. int  argc; char  *argv[];
  217. /* first argument: comment leader; 2nd: log message, 3rd: expanded file,
  218.  * 4th: unexpanded file
  219.  */
  220. {       struct hshentry delta;
  221.  
  222.         cmdid="rcsfcmp";
  223.         Comment=argv[1];
  224.         delta.log=argv[2];
  225.         if (rcsfcmp(argv[3],argv[4],&delta))
  226.                 VOID printf("files are the same\n");
  227.         else    VOID printf("files are different\n");
  228. }
  229. #endif
  230.